/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaServices;

import entities.MyBatisUtil;
import entities.Photo;
import java.util.List;
import org.apache.ibatis.session.SqlSession;

/**
 *
 * @author michael
 */
public class PhotoManager {
    
    public static Photo getById(int userId) {
	  SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
	  try{
	  Photo userMapper = sqlSession.selectOne("mapper.PhotoMapper.getById", userId);
	  return userMapper;
	  }finally{
	   sqlSession.close();
	  }
	 }
    
    public static List<Photo> getAll(){
        
        SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
	  try{
	  List<Photo> userMapper = sqlSession.selectList("mapper.PhotoMapper.getAll");
	  return userMapper;
	  }finally{
	   sqlSession.close();
	  }
    }
    
    public static void insertPhoto(Photo photo) {
	  SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
	  try{
	  sqlSession.insert("mapper.PhotoMapper.insertPhoto", photo);	  
	  sqlSession.commit();
	  }finally{
	   sqlSession.close();
	  }
	 }
    
    public static void updatePhoto(int idPhoto) {
	  SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
	  try{
	  sqlSession.update("mapper.PhotoMapper.insertPhoto", idPhoto);	  
	  sqlSession.commit();
	  }finally{
	   sqlSession.close();
	  }
	 }
}
